package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.Carproduct;
import com.olddriver.crm.mapper.CarproductMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.CarproductQueryObject;
import com.olddriver.crm.service.ICarproductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by 季节 on 2017/12/4
 */
@Service
public class CarproductServiceImpl implements ICarproductService {

    @Autowired
    private CarproductMapper carproductMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return carproductMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Carproduct record) {
        return carproductMapper.insert(record);
    }

    @Override
    public Carproduct selectByPrimaryKey(Long id) {
        return carproductMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Carproduct> selectAll() {
        return carproductMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Carproduct record) {
        return carproductMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult query(CarproductQueryObject qo) {
      int  total =  carproductMapper.queryForTotal(qo);
      if(total == 0){

          return  new PageResult(total, Collections.emptyList());
      }


          return new PageResult(total,carproductMapper.queryForRows(qo));
    }

    @Override
    public void changeState(Long id) {
        carproductMapper.changeState(id);
    }

    @Override
    public List<Carproduct> getCarproductByMechId(Long id) {
        return carproductMapper.getCarproductByMechId(id);
    }
}
